/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.nanosn.coffeemaker.datebase;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 *
 * @author selkhateeb
 */
public class Select {

    private static String SELECT = "SELECT";
    private List<String> columns;
    private From from;

    protected List<String> getColumns() {
        return columns;
    }

    public Select() {
        this.columns = new ArrayList<String>();
    }

    public Select(Class<?> entity) {
        this();
        this.columns.add(entity.getSimpleName());
    }

    public Select(String... columns) {
        this();
        this.columns.addAll(Arrays.asList(columns));
    }

    public From From(Class<?>... entities) {
        from = new From(entities);
        this.from.setSelect(this);
        return from;
    }

    @Override
    public String toString() {
        String query = SELECT;

        for (String column : columns) {
            query += " " + column;
        }

        query += " " + from.getClause();

        return query;

    }
}
